import { defineStore } from 'pinia'
export const useUserStore = defineStore('user',{
	  
	  state: () => ({
	    userInfo: null, // 用户信息
	    token: uni.getStorageSync("token"), // 用户登录 token
	    isLoggedIn: false, // 用户是否登录状态
		statusBarHeight:0
	  }),
	  actions: {
		setStatusBarHeight(){
			const info = uni.getSystemInfoSync();
			this.statusBarHeight = info.statusBarHeight;
		},
	    setUserInfo(info) {
			this.userInfo = info;
			this.isLoggedIn = true;
	    },
	    setToken(token) {
			this.token = token;
			if (token) {
				uni.setStorage({
					key: "token",
					data: token
				})
			} else {
				uni.removeStorage({
					key: "token",
				})
			}
	    },
	    logout() {
			this.userInfo = null;
			this.token = '';
			this.isLoggedIn = false;
	    }
	  },
})